﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using ModuleDALCore;
using DTO;

namespace DAL
{
	public class KHODAO:DALBase
	{
		public KHODAO()
		{
			this.OpenConnect();
		}
		private DataTable dt;
		private string _SpName;
		public string SpName
		{
			get { return "SPKHO"; }
			set { _SpName = value; }
		}
		public DataTable GetListKHO()
		{
			dt = new DataTable();
			try
			{
				dt = DBManager.Intance.ExecuteDataTable(SpName, ConvertClassToArray.GetParamName(new KHOS(), null), ConvertClassToArray.GetValues(new KHOS(), 0));
				return dt;
			}
			catch { return null; }
		}
		public List<KHOS> GetListKHOs()
		{
			dt = new DataTable();
			List<KHOS> ds = new List<KHOS>();
			try
			{

				dt = DBManager.Intance.ExecuteDataTable(SpName, ConvertClassToArray.GetParamName(new KHOS(), null), ConvertClassToArray.GetValues(new KHOS(), 0));
				ds = (List<KHOS>)ConvertDatatableToList.ConvertTo<KHOS>(dt);
				return ds;
			}
			catch { return null; }// throw new InvalidExpressionException("Msg1: Can't list KHOS"); }
		}
		public String CreatenewId()
		{
			try
			{
				return "KH" + DBManager.Intance.ExecuteNonQuery(SpName, ConvertClassToArray.GetParamName(new KHOS(), null), ConvertClassToArray.GetValues(new KHOS(), 1));

			}
			catch { return null; }//throw new InvalidExpressionException("Msg1: Can't Create new KHOS"); }
		}
		public bool INSERT(KHOS KH)
		{

			try
			{
				return (DBManager.Intance.ExecuteNonQuery(SpName, ConvertClassToArray.GetParamName(KH, null), ConvertClassToArray.GetValues(KH, 2)) == 1);

			}
			catch { return false; }//throw new InvalidExpressionException("Msg1: Can't Insert new KHOS"); }
		}
		public bool UPDATE(KHOS KH)
		{

			try
			{
				return (DBManager.Intance.ExecuteNonQuery(SpName, ConvertClassToArray.GetParamName(KH, null), ConvertClassToArray.GetValues(KH, 3)) == 1);

			}
			catch { return false; }//throw new InvalidExpressionException("Msg1: Can't Update  KHOS"); }
		}
		public bool DELETE(KHOS KH)
		{

			try
			{
				return (DBManager.Intance.ExecuteNonQuery(SpName, ConvertClassToArray.GetParamName(KH, null), ConvertClassToArray.GetValues(KH, 4)) == 1);

			}
			catch { return false; }//throw new InvalidExpressionException("Msg1: Can't Delete  KHOS"); }
		}
	}
}
